-- 导入所需的模块
local class = require("Utils.ClassUtils").class
local Consts = require("Data.Consts")
local MathUtils = require("Utils.MathUtils")

---@class GenerateController
---@field new fun(): GenerateController
local GenerateController = class("GenerateController")

---构造函数
function GenerateController:ctor()
    self.offset = 3
end

function GenerateController:generateObjects(startPoint, objId, x, z, role)
    --     -- 获取起始点坐标
    local startPos = startPoint.get_position()
    local Vector3 = math.Vector3
    local Quaternion = math.Quaternion

    --         -- 在x*z的网格中生成物体
    for i = 1, x do
        for j = 1, z do
            -- 计算偏移位置 (每个物体间隔1个单位)
            local offsetX = startPos.x + (j - 1) * self.offset
            local offsetZ = startPos.z + (i - 1) * self.offset
            local orientation = Quaternion(0.0, 0.0, 0.0)
            local scale = Vector3(1.0, 1.0, 1.0)
            --                 -- 创建新位置向量
            local newPos = math.Vector3(offsetX, startPos.y, offsetZ)

            --     local tmp=GameAPI.create_obstacle(objId, newPos, orientation, scale, role)
            -- tmp
            G.prefabFactory:createPrefabWithCb(Consts.PrefabType.UNIT_OBSTACLE, objId, newPos, math.Quaternion(0, 0, 0),
                scale, function(unit)
                     unit.set_kv_by_type(Enums.ValueType.Int, "hp", 2)

                end)
        end
    end
end

return GenerateController
